package com.example.robotwatcher;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.TextureView;
import android.view.View;

import com.example.robotwatcher.backend.DataCollector;
import com.example.robotwatcher.backend.DataVisualization;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;

import java.util.ArrayList;
import java.util.List;

public class Demo extends AppCompatActivity {
    VideoSurfaceView showVideo;
    SurfaceViewDemo demo;
    TextureView textureView;
    DataCollector collector;
    DataVisualization chart;
    int count = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        chart = new DataVisualization();
//==========================画圆测试=====================
//        demo = new SurfaceViewDemo(this);
        setContentView(R.layout.demo);
        VideoSurfaceView view = findViewById(R.id.surfaceView);
        view.Start();

//=================单独surfaceView视频展示============
//        showVideo = new VideoSurfaceView(this);
//        setContentView(R.layout.activity_main);

//================网络通讯收发数据====================
//        collector = new DataCollector();
//        collector.setTargetUrl("172.24.89.254");

//===============LineChar test====================

//        LineChart mLineChart = (LineChart) findViewById(R.id.mDetailLineChart);
//        //显示边界
//        mLineChart.setDrawBorders(true);
//        //设置数据
//        List<Entry> entries = new ArrayList<>();
//        for (int i = 0; i < 10; i++) {
//            entries.add(new Entry(i, (float) (Math.random()) * 80));
//        } //一个LineDataSet就是一条线
//        LineDataSet lineDataSet = new LineDataSet(entries, "温度");
//        LineData data = new LineData(lineDataSet);
//        mLineChart.setData(data);


        LineChart mlineChart = (LineChart) findViewById(R.id.mDetailLineChart);
        chart.addLineChart(mlineChart);

    }

    public void Restart(View view) {
        VideoSurfaceView v = findViewById(R.id.surfaceView);
        v.RetryOnline();
    }

    public void getDeviceInfo(View view)
    {
        collector.getDeviceInfo();
    }

    public void getStateInfo(View view)
    {
        new Thread(new Runnable() {
            @Override
            public void run() {
                collector.getStateInfo();

            }
        }).start();

    }

    public void getSystemInfo(View view)
    {
        new Thread(new Runnable() {
            @Override
            public void run() {

                collector.getSystemInfo();


            }
        }).start();
    }

    public void Click_On(View view)
    {
        switch (view.getId())
        {
            case R.id.surfaceView:
                break;
            case R.id.mDetailLineChart:
                break;
            case R.id.button5:
            {
                count =( count +  1)%30 ;
                chart.addData(0,0,count);
                break;
            }

            default:
                break;
        }
    }
}